package com.szq.netty.test;

import com.alibaba.fastjson.JSON;
import com.szq.netty.client.ClientSocket;
import com.szq.netty.future.SyncWrite;
import com.szq.netty.msg.Request;
import com.szq.netty.msg.Response;
import io.netty.channel.ChannelFuture;

/**
 * @ClassName: StartClient
 * @Description:
 * @Author: szq
 * @Date: 2021-11-17 10:03:00
 */
public class StartClient {

    private static ChannelFuture future;

    public static void main(String[] args) {
        ClientSocket client = new ClientSocket();
        new Thread(client).start();

        while (true){
            try{
                //获取future,线程有等待处理时间
                if (null == future){
                    future = client.getFuture();
                    Thread.sleep(500);
                    continue;
                }
                //构建发送参数
                Request request = new Request();
                request.setResult("查询用户信息");
                SyncWrite syncWrite = new SyncWrite();
                Response response = syncWrite.writeAndSync(future.channel(), request, 200);
                System.out.println("调用结果：" + JSON.toJSON(response));
                Thread.sleep(1000);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
